package com.probox.modules.controller.customer;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.entity.domain.customer.CustomerTaskInfoRecord;
import com.probox.common.entity.service.customer.ICustomerTaskInfoRecordService;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 会员完成任务Controller
 *
 * @author usoft
 * @date 2022-09-19
 */
@RestController
@RequestMapping("/customer/taskRecord")
public class CustomerTaskInfoRecordController extends BaseController
{
    @Autowired
    private ICustomerTaskInfoRecordService customerTaskInfoRecordService;

/**
 * 查询会员完成任务列表
 */
@GetMapping("/list")
    public TableDataInfo list(CustomerTaskInfoRecord customerTaskInfoRecord)
    {
        startPage();
        List<CustomerTaskInfoRecord> list = customerTaskInfoRecordService.queryListA(customerTaskInfoRecord);
        return getDataTable(list);
    }



    /**
     * 导出会员完成任务列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerTaskInfoRecord customerTaskInfoRecord) throws IOException
    {
        List<CustomerTaskInfoRecord> list = customerTaskInfoRecordService.queryList(customerTaskInfoRecord);
        ExcelUtil<CustomerTaskInfoRecord> util = new ExcelUtil<CustomerTaskInfoRecord>(CustomerTaskInfoRecord.class);
        util.exportExcel(response, list, "会员完成任务数据");
    }

    /**
     * 获取会员完成任务详细信息
     */
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(customerTaskInfoRecordService.selectCustomerTaskInfoRecordById(recordId));
    }

    /**
     * 新增会员完成任务
     */
    @PostMapping("/addTask")
    public AjaxResult add(@RequestBody CustomerTaskInfoRecord customerTaskInfoRecord)
    {
        return toAjax(customerTaskInfoRecordService.insertCustomerTaskInfoRecord(customerTaskInfoRecord));
    }

    /**
     * 修改会员完成任务
     */
    @PreAuthorize(hasPermi ="system:rule:edit")
    @PutMapping("/updateTask")
    public AjaxResult edit(@RequestBody CustomerTaskInfoRecord customerTaskInfoRecord)
    {
        return toAjax(customerTaskInfoRecordService.updateCustomerTaskInfoRecord(customerTaskInfoRecord));
    }

    /**
     * 修改会员完成任务状态
     */
    @PreAuthorize(hasPermi = "system:brand:edit")
    @Log(title = "商品设备", businessType = BusinessType.UPDATE)
    @PutMapping("/updateBrandStatus")
    public AjaxResult editA(@RequestBody CustomerTaskInfoRecord customerTaskInfoRecord)
    {
        return toAjax(customerTaskInfoRecordService.updateCustomerTaskInfoRecord(customerTaskInfoRecord));
    }

    /**
     * 删除会员完成任务
     */
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(customerTaskInfoRecordService.deleteCustomerTaskInfoRecordByIds(recordIds));
    }
}
